package pl.puntin.punclient.messages;

import java.util.HashMap;


/**
 * Singleton z leniwa inicalizacja
 * @author kakus
 *
 */
public class MessageTypesMap
{
	private static HashMap<Byte, Class<? extends Message>> typesMap;
	
	private static void initMapTypes()
	{
		typesMap = new HashMap<Byte, Class<? extends Message>>();
		
		/**
		 * Rejestracja
		 */
		typesMap.put(MessageTypes.CHECK_CONNECTION, CheckConnectionMessage.class);
		typesMap.put(MessageTypes.CHAT_MESSAGE, ChatMessage.class);
		typesMap.put(MessageTypes.IMAGE_MESSAGE, ImageMessage.class);
		typesMap.put(MessageTypes.S_LOGIN_OK, LoginOkMessage.class);
		typesMap.put(MessageTypes.S_LOGIN_FALSE, LoginFalseMessage.class);
		typesMap.put(MessageTypes.S_PUN_FOR_DRAWER, PunMessage.class);
	}
	
	public static Class<? extends Message> getClass(final byte code)
	{
		if(typesMap == null)
			initMapTypes();
		
		return typesMap.get(code);
	}
}
